# Author: HZT
# Date: 2023/11/9
import time
import page
from base.base import Base
from selenium.webdriver.support.select import Select

from utils import click_paste_img


class WebDfJd(Base):
    # 点击代付交易处理
    def df_jd_click_dfjycl(self):
        self.base_click(page.web_df_jd_dfjycl)

    # 点击开始接单
    def df_jd_click_ksjd(self):
        # 定位开关元素
        switch = self.base_find(page.web_df_jd_ksjd)
        # 判断开关状态
        if switch.get_attribute("aria-hidden") == "true":
            # 开关是关闭状态，点击开关
            self.base_click(page.web_df_jd_ksjd)

    # 点击确认成功
    def df_jd_click_qrcg(self):
        self.base_click(page.web_df_jd_qrcg)

    # 点击确认失败
    def df_jd_click_qrsb(self):
        self.base_click(page.web_df_jd_qrsb)

    # 获取成功图片元素
    def df_jd_get_cgtp(self):
        return self.base_find(page.web_df_jd_cgtp)

    # 点击成功提交
    def df_jd_click_cgtj(self):
        self.base_click(page.web_df_jd_cgtj)

    # 点击确认查看
    def df_jd_click_qrck(self):
        self.base_click(page.web_df_jd_qrck)

    # 点击取消
    def df_jd_click_qx(self):
        self.base_click(page.web_df_jd_qx)

    # 输入失败备注
    def df_jd_input_sbbz(self, text):
        self.base_input(page.web_df_jd_sbbz, text)

    # 点击失败提交
    def df_jd_click_sbtj(self):
        self.base_click(page.web_df_jd_sbtj)

    # 处理退款请求
    def df_jd_click_cltkqq(self):
        self.base_click(page.web_df_jd_cltkqq)

    # 拒绝退款
    def df_jd_click_jjtk(self):
        self.base_click(page.web_df_jd_jjtk)

    # 同意退款
    def df_jd_click_tytk(self):
        self.base_click(page.web_df_jd_tytk)

    # 退款说明
    def df_jd_input_tksm(self, text):
        self.base_input(page.web_df_jd_tksm, text)

    # 退款图片
    def df_jd_get_tktp(self):
        return self.base_find(page.web_df_jd_tktp)

    # 退款提交
    def df_jd_click_tktj(self):
        self.base_click(page.web_df_jd_tktj)

    def df_yy(self):
        select = Select(self.base_find(page.web_df_yy))
        current_option = select.first_selected_option.text
        if current_option == 'English':
            select.select_by_value("zh-CN")

    # 确认成功
    def df_jd_qrcg(self, driver):
        self.df_jd_click_qrcg()
        element = self.df_jd_get_cgtp()
        click_paste_img("test001.png", element, driver)
        self.df_jd_click_cgtj()

    # 确认成功
    def df_jd_qrsb(self, driver):
        self.df_jd_click_qrsb()
        self.df_jd_input_sbbz("heihei")
        self.df_jd_click_sbtj()

    # 拒绝退款
    def df_jd_jjtk(self, driver):
        self.df_jd_click_cltkqq()
        self.df_jd_click_jjtk()
        self.df_jd_input_tksm("不行")
        element = self.df_jd_get_tktp()
        click_paste_img("test002.png", element, driver)
        self.df_jd_click_tktj()

    # 同意退款
    def df_jd_tytk(self, driver):
        self.df_jd_click_cltkqq()
        self.df_jd_click_tytk()
        self.df_jd_input_tksm("行")
        element = self.df_jd_get_tktp()
        click_paste_img("test002.png", element, driver)
        self.df_jd_click_tktj()
